package servlet.rool;

import net.sf.json.JSONObject;
import service.AdminService;
import service.impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 修改密码的servlet
 */
@WebServlet(value = "/ModifyPasswordServlet")
public class ModifyPasswordServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id=request.getParameter("id");
        String password=request.getParameter("newPassword");
        AdminService as=new AdminServiceImpl();
        int bo=as.modifPassword(password,Integer.parseInt(id));
        JSONObject json=new JSONObject();
        if(bo>0){
            json.put("msg","密码修改成功");
        }else {
            json.put("msg","密码修改失败");
        }
        PrintWriter out=response.getWriter();
        out.print(json);

    }
    
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
        doGet(request, response);
    }
}
